home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / MAP Viewer / World.h < prev    next >
C/C++ Source or Header  |  2003-10-09  |  5KB  |  255 lines

  1. /*
  2. Half-Life MAP viewing utility.
  3. Copyright (C) 2003  Ryan Samuel Gregg
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #pragma once
  21. #include "stdafx.h"
  22. #include "WorldObject.h"
  23. #include "Brush.h"
  24. #include "Entity.h"
  25. #include "Frustum.h"
  26. #include "TextureManager.h"
  27.  
  28. __sealed __gc class CWorld : public CWorldObject
  29. {
  30. private:
  31.     int iBrushCount;
  32.     ArrayList *Entities;
  33.  
  34. public:
  35.     CWorld(CConfig *Config) : CWorldObject(Config)
  36.     {
  37.         Entities = new ArrayList();
  38.     }
  39.  
  40.     void AddEntity(CEntity *Entity)
  41.     {
  42.         Entities->Add(Entity);
  43.     }
  44.  
  45.     ArrayList *GetEntities()
  46.     {
  47.         return Entities;
  48.     }
  49.  
  50.     int GetBrushCount()
  51.     {
  52.         return iBrushCount;
  53.     }
  54.  
  55.     bool GetWADString(String **sWADString)
  56.     {
  57.         if(Entities->Count == 0)
  58.             return false;
  59.  
  60.         ArrayList *ArgVals;
  61.         CArgVal *ArgVal;
  62.         ArgVals = static_cast<CEntity*>(Entities->get_Item(0))->GetArgVals();
  63.  
  64.         for(int i = 0; i < ArgVals->Count; i++)
  65.         {
  66.             ArgVal = static_cast<CArgVal*>(ArgVals->get_Item(i));
  67.             if(ArgVal->GetArg()->ToLower()->Equals("wad"))
  68.             {
  69.                 *sWADString = ArgVal->GetVal();
  70.                 return true;
  71.             }
  72.         }
  73.  
  74.         return false;
  75.     }
  76.  
  77.     void UpdateBrushCount()
  78.     {
  79.         iBrushCount = 0;
  80.  
  81.         for(int i = 0; i < Entities->Count; i++)
  82.         {
  83.             iBrushCount += static_cast<CEntity*>(Entities->get_Item(i))->GetBrushCount();
  84.         }
  85.     }
  86.  
  87.     void UpdateBoundingBoxes()
  88.     {
  89.         for(int i = 0; i < Entities->Count; i++)
  90.         {
  91.             static_cast<CEntity*>(Entities->get_Item(i))->UpdateBoundingBoxes();
  92.         }
  93.     }
  94.  
  95.     void UpdateColors()
  96.     {
  97.         Random *Rnd = new Random();
  98.         CEntity *Entity;
  99.  
  100.         for(int i = 0; i < Entities->Count; i++)
  101.         {
  102.             Entity = static_cast<CEntity*>(Entities->get_Item(i));
  103.             Entity->SetColor(Rnd->Next(256), Rnd->Next(256), Rnd->Next(256));
  104.  
  105.             for(int j = 0; j < Entity->GetBrushes()->Count; j++)
  106.             {
  107.                 static_cast<CBrush*>(Entity->GetBrushes()->get_Item(j))->SetColor(Rnd->Next(256), Rnd->Next(256), Rnd->Next(256));
  108.             }
  109.         }
  110.     }
  111.  
  112.     void CullWorld(CFrustum *Frustum)
  113.     {
  114.         for(int i = 0; i < Entities->Count; i++)
  115.         {
  116.             static_cast<CEntity*>(Entities->get_Item(i))->CullEntity(Frustum);
  117.         }
  118.     }
  119.  
  120.     void UpdateTexCoords(CTextureManager *TextureManager)
  121.     {
  122.         for(int i = 0; i < Entities->Count; i++)
  123.         {
  124.             static_cast<CEntity*>(Entities->get_Item(i))->UpdateTexCoords(TextureManager);
  125.         }
  126.     }
  127.  
  128.     void DrawWorldTextured()
  129.     {
  130.         glEnable(GL_CULL_FACE);
  131.         glEnable(GL_DEPTH_TEST);
  132.         glEnable(GL_TEXTURE_2D);
  133.         glColor3ub(255, 255, 255);
  134.  
  135.         if(Config->bLightScene)
  136.         {
  137.             glEnable(GL_LIGHTING);
  138.             glEnable(GL_LIGHT0);
  139.             glEnable(GL_LIGHT1);
  140.         }
  141.  
  142.         if(Config->bFog)
  143.         {
  144.             glEnable(GL_FOG);
  145.         }
  146.  
  147.         for(int i = 0; i < Entities->Count; i++)
  148.         {
  149.             static_cast<CEntity*>(Entities->get_Item(i))->DrawEntityTextured();
  150.         }
  151.  
  152.         if(Config->bFog)
  153.         {
  154.             glDisable(GL_FOG);
  155.         }
  156.  
  157.         if(Config->bLightScene)
  158.         {
  159.             glDisable(GL_LIGHT0);
  160.             glDisable(GL_LIGHT1);
  161.             glDisable(GL_LIGHTING);
  162.         }
  163.     }
  164.  
  165.     void DrawWorldSolid()
  166.     {
  167.         glEnable(GL_CULL_FACE);
  168.         glEnable(GL_DEPTH_TEST);
  169.         glDisable(GL_TEXTURE_2D);
  170.  
  171.         if(Config->bLightScene)
  172.         {
  173.             glEnable(GL_LIGHTING);
  174.             glEnable(GL_LIGHT0);
  175.             glEnable(GL_LIGHT1);
  176.         }
  177.  
  178.         if(Config->bFog)
  179.         {
  180.             glEnable(GL_FOG);
  181.         }
  182.  
  183.         for(int i = 0; i < Entities->Count; i++)
  184.         {
  185.             static_cast<CEntity*>(Entities->get_Item(i))->DrawEntitySolid();
  186.         }
  187.  
  188.         if(Config->bFog)
  189.         {
  190.             glDisable(GL_FOG);
  191.         }
  192.  
  193.         if(Config->bLightScene)
  194.         {
  195.             glDisable(GL_LIGHT0);
  196.             glDisable(GL_LIGHT1);
  197.             glDisable(GL_LIGHTING);
  198.         }
  199.     }
  200.  
  201.     void DrawWorldWireFrame()
  202.     {
  203.         glDisable(GL_CULL_FACE);
  204.         glDisable(GL_DEPTH_TEST);
  205.         glDisable(GL_TEXTURE_2D);
  206.  
  207.         for(int i = 0; i < Entities->Count; i++)
  208.         {
  209.             static_cast<CEntity*>(Entities->get_Item(i))->DrawEntityWireFrame();
  210.         }
  211.     }
  212.  
  213.     void DrawWorldPoints()
  214.     {
  215.         glDisable(GL_CULL_FACE);
  216.         glDisable(GL_DEPTH_TEST);
  217.         glDisable(GL_TEXTURE_2D);
  218.  
  219.         for(int i = 0; i < Entities->Count; i++)
  220.         {
  221.             static_cast<CEntity*>(Entities->get_Item(i))->DrawEntityPoints();
  222.         }
  223.     }
  224.  
  225.     void Highlight(bool bPrepared)
  226.     {
  227.         if(!bPrepared)
  228.         {
  229.             PrepareHighlight();
  230.         }
  231.  
  232.         for(int i = 0; i < Entities->Count; i++)
  233.         {
  234.             static_cast<CEntity*>(Entities->get_Item(i))->Highlight(true);
  235.         }
  236.     }
  237.  
  238.     void Outline()
  239.     {
  240.         glEnable(GL_CULL_FACE);
  241.         glEnable(GL_DEPTH_TEST);
  242.         glDisable(GL_TEXTURE_2D);
  243.         
  244.         glColor4f(Config->cOutlineColor.R, Config->cOutlineColor.G, Config->cOutlineColor.B, Config->cOutlineColor.A);
  245.  
  246.         glDepthFunc(GL_LEQUAL);
  247.  
  248.         for(int i = 0; i < Entities->Count; i++)
  249.         {
  250.             static_cast<CEntity*>(Entities->get_Item(i))->Outline();
  251.         }
  252.  
  253.         glDepthFunc(GL_LESS);
  254.     }
  255. };